package com.cloud.custom.tasklist.web;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.custom.common.result.Quokka;
import com.cloud.custom.common.utils.SessionHelper;
import com.cloud.custom.interfaces.FeignClientForm;
import com.cloud.custom.tasklist.service.TaskListTabFormService;
import com.cloud.custom.workflow.entity.WfActInst;

/**
 * 表单面板相关逻辑
 * 
 * @author Minglong.tao
 *
 */
@RestController
@RequestMapping("/custom/api/tab/form")
public class TaskListTabFormController {
	@Autowired
	private TaskListTabFormService recFormService;
	@Autowired
	private FeignClientForm feignClientForm;

	/**
	 * 获取案卷当前所属环节可填写文书
	 * 
	 * @param recId
	 * @return
	 */
	@GetMapping("listformtree")
	public Quokka listFormTree(long recId, long actDefId) {
		if (actDefId <= 0) {
			WfActInst actInst = recFormService.loadActInst(recId, SessionHelper.get().getParts());
			if (null != actInst) {
				actDefId = actInst.getActDefId();
			}
		}
		return new Quokka(true,
				feignClientForm.listFormTree(recId, actDefId, StringUtils.join(SessionHelper.get().getParts(), ",")));
	}

	/**
	 * 获取案卷当前所属环节可填写文书
	 * 
	 * @param recId
	 * @return
	 */
	@GetMapping("listprintformtree")
	public Quokka listPrintFormTree(long recId, long actDefId) {
		if (actDefId <= 0) {
			WfActInst actInst = recFormService.loadActInst(recId, SessionHelper.get().getParts());
			if (null != actInst) {
				actDefId = actInst.getActDefId();
			}
		}
		return new Quokka(true, feignClientForm.listPrintFormTree(recId, actDefId,
				StringUtils.join(SessionHelper.get().getParts(), ",")));
	}
}
